package edu.neusoft.yiqibike.controller;

import com.baomidou.mybatisplus.plugins.Page;
import edu.neusoft.yiqibike.common.entity.mysql.AccountLog;
import edu.neusoft.yiqibike.common.entity.mysql.User;
import edu.neusoft.yiqibike.common.entity.vo.AccountVo;
import edu.neusoft.yiqibike.common.entity.vo.Response;
import edu.neusoft.yiqibike.common.exception.ArgumentVerifyException;
import edu.neusoft.yiqibike.service.IAccountService;
import edu.neusoft.yiqibike.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * User：lyc
 * Date：2017-12-20
 * Time：22:54
 * Description：
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;
    @Autowired
    private IAccountService accountService;

    @PostMapping("/list")
    public Response<Page<User>> getUserList(@RequestBody Page<User> page) {
        return Response.success(userService.getUserList(page));
    }

    @PostMapping("/account")
    public Response<AccountVo> getAccountInfo(@RequestBody Page<AccountLog> page) {
        return Response.success(accountService.getAccountInfo(page));
    }

    @PostMapping("/limit")
    public Response<String> limit(@RequestBody User user) {
        if (Objects.isNull(user) || Objects.isNull(user.getId()) || Objects.isNull(user.getIsEnable())) {
            throw new ArgumentVerifyException("检测到非法参数");
        }
        userService.invertIsEnable(user.getId(), user.getIsEnable());
        return Response.success();
    }
}
